package org.example.service.direct;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 * @author Tang
 * @classname DirectSender
 * @description [  ]
 * @date 2023/4/10 22:06
 */
//@Component
public class DirectSender implements CommandLineRunner {

    @Resource
    RabbitTemplate rabbitTemplate;

    @Override
    public void run(String... args) throws Exception {
        final Message infoMsg = MessageBuilder
                .withBody("info msg".getBytes(StandardCharsets.UTF_8))
                .setContentType(MessageProperties.CONTENT_TYPE_BYTES)
//                .setMessageId(UUID.randomUUID().toString())
                .build();
        final Message errorMsg = MessageBuilder
                .withBody("error msg".getBytes(StandardCharsets.UTF_8))
                .setContentType(MessageProperties.CONTENT_TYPE_BYTES)
//                .setMessageId(UUID.randomUUID().toString())
                .build();
        rabbitTemplate.convertAndSend("info-exchange","info-key", "info msg");
        rabbitTemplate.convertAndSend("error-exchange","error-key", "error msg");
    }

}
